<?php
/**
 * Created by PhpStorm.
 * User: chase
 * Date: 2017/8/29
 * Time: 9:23
 */

namespace app\mobile\controller;

use cmf\controller\AdminBaseController;
use app\course\service\CourseTeacherStatisticsService;
use think\Db;


class ScheduleController extends AdminBaseController
{
    public function index()
    {
        $param['admin_shop_id'] = $this->admin_shop_id;
        $tid = cmf_get_current_admin_id();
        $param = $this->request->param();

        $service = new CourseTeacherStatisticsService();
        $data = $service->getClassList($tid, $param);
        $page=$data->render();

        $this->assign('param', $param);
        $this->assign('page', $page);
        $this->assign('data', $data);
        return $this->fetch();

    }


    public function courseList()
    {
        $param['admin_shop_id'] = $this->admin_shop_id;
        $tid = cmf_get_current_admin_id();
        $service = new CourseTeacherStatisticsService();
        $data = $service->getCourseList($tid);
//        dump($data);
        $this->assign('page', $data->render());
        //重新排序
        foreach ($data as $k => $v) {
            $j = $k + 1;
            foreach ($data as $j => $val) {
                if (isset($data[$j])) {
                    if(!empty($val['supply_teacher']))
                    {
                        $data[$k]['supply_teacher']=Db::name('user')->where(['id'=>$val['supply_teacher']])->value('user_login');
                    }
                    $before = $data[$k]['date'];
                    $after = $data[$j]['date'];
                    if ($before < $after) {
                        $t = $data[$j];
                        $data[$j] = $data[$k];
                        $data[$k] = $t;
                    }
                }
                $teacher_id = $data[$k]['teacher_id'];
            }
        }
        $this->assign('teacher_id', $teacher_id);
        $this->assign('data', $data);
        return $this->fetch('courselist');
    }



}